import React, {Suspense, useEffect} from 'react';
import {BrowserRouter as Router, Routes, Route, Navigate} from 'react-router-dom'
import {Spin} from 'antd'
import Login from "./components/Login";
import FrameLayout from "./components/FrameLayout";
import AuthProvider from "./router/AuthProvider";
import AuthorizedRouter from "./router/AuthorizedRouter";
import Setting from "./components/Setting";
// import routesMap from './router';
import routeMapList from './router'
import NotFound from './components/pages/NotFound';
import Dashboard from './components/Dashboard';
import Loading from "./view/Loading";

function Page() {

    useEffect(() => {

    }, []);


    return (
        <Router>
            <Suspense
                fallback={
                    <Loading/>
                }
            >
                <AuthProvider>
                    <Routes>
                        <Route path="/login" element={<Login/>}/>
                        <Route path="/app" element={<FrameLayout/>}>
                            <Route index element={<AuthorizedRouter>{< Dashboard/>}</AuthorizedRouter>}/>
                            {routeMapList.map((route, index) => (
                                <Route
                                    key={route.path as string}
                                    path={route.path as string}
                                    element={
                                        <AuthorizedRouter>
                                            {< route.component/>}
                                        </AuthorizedRouter>
                                    }/>
                            ))}
                            <Route path="*" element={<Navigate to="/404"/>}/>
                        </Route>

                        <Route path="*" element={<Navigate to="/app"/>}/>
                        <Route path="/404" element={<NotFound/>}></Route>
                    </Routes>
                </AuthProvider>

            </Suspense>
        </Router>

    );
}

export default Page;


/* <Route path="/app/setting" element={
                            <AuthProvider>
                             <Setting/>
                            </AuthProvider>

                        }></Route>*/
